package role

import (
	"context"
	"jinrigaoping/api/platform/internal/svc"
	"jinrigaoping/api/platform/internal/types"

	"jinrigaoping/rpc/sys/sys"

	"github.com/zeromicro/go-zero/core/logx"
)

type RoleSelectLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewRoleSelectLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RoleSelectLogic {
	return &RoleSelectLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *RoleSelectLogic) RoleSelect(req *types.SysRoleSelectReq) (resp *types.SysRoleSelectRes, err error) {

	pageResp, err := l.svcCtx.SysRpc.SysRoleSelect(l.ctx, &sys.SysRoleSelectReq{})

	if err != nil {
		return nil, err
	}

	var list = make([]*types.SysRoleSelectItem, len(pageResp.List))

	for i, v := range pageResp.List {
		list[i] = &types.SysRoleSelectItem{
			Id:       v.Id,
			RoleName: v.RoleName,
		}
	}

	return &types.SysRoleSelectRes{
		List: list,
	}, nil
}
